package com.ynhenc.pta.routeRank.impl;

import java.awt.geom.Point2D;
import java.io.*;

import com.ynhenc.comm.*;
import com.ynhenc.comm.db.*;
import com.ynhenc.comm.util.FileUtil;
import com.ynhenc.pta.routeRank.*;
import com.ynhenc.pta.routeRank.sql.*;

public class ComLib_PTA extends GisComLib {

	public QueryResult getQueryResult(String sql) throws Exception {
		Database db = this.getOracleDb();
		return db.getQueryResult(sql, SysConfPta.SQL_DEBUG );
	}

	public SQL getSQL( String sqlPathName ) throws Exception {
		return new SqlGetterPta().getSql( sqlPathName );
	}

	private Database getOracleDb() {

		if (ORACLE_DB == null) {

			NetAddr oracleNetAddr = RouteRequestImpl.getOracleServerAddr();

			if( oracleNetAddr == null ) {
				oracleNetAddr = SysConfPta.NET_ADDR_02_ORACLE;
			}

			this.debug( "Oracle Server: " + oracleNetAddr );

			String host = oracleNetAddr.getHostName();
			int port = oracleNetAddr.getPortNo();

			String sid = SysConfPta.OracleSid;
			String user = SysConfPta.OracleUser;
			String passwd = SysConfPta.OraclePaswd;

			String dbUrl = Database_02_Oracle.getDbUrl_Oracle(host, sid, port, user, passwd);

			Database db = new Database_02_Oracle(dbUrl);

			ORACLE_DB = db;

		}

		return ORACLE_DB;
	}

	private static Database ORACLE_DB;

}
